import 'package:flutter/material.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/widgets/pull/nested/simple_pull_load_manger.dart';
import 'package:flutterlib/widgets/pull/nested/simple_pull_load_page_widget.dart';

abstract class BaseSliverList extends StatefulWidget {
  BaseSliverList({Key key}) : super(key: key);

  @override
  BaseSliverListState createState();
}

///页面 KeepAlive ，同时支持 动画Ticker
abstract class BaseSliverListState<T extends BaseSliverList> extends State<T>
    with TickerProviderStateMixin {
  SimplePullLoadManger manger;

  ///滑动监听
  final ScrollController scrollController = new ScrollController();

  getDataLogic(int page);

  Widget renderItem(index, interest);

  List<Widget> renderHeader(BuildContext context, bool innerBoxIsScrolled);

  bool enablePullUp();

  bool enablePullDown();

  @override
  void initState() {
    super.initState();
    manger = SimplePullLoadManger.needSliverHeader(
      getDataLogic: getDataLogic,
      renderItem: renderItem,
      renderHeader: renderHeader,
      enablePullUp: enablePullUp(),
      enablePullDown: enablePullDown(),
    );
  }

  Widget renderTitle();

  Widget renderLeading();

  renderActions();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: QuhuiColors.mainBackgroundColor,
        title: renderTitle(),
        leading: renderLeading(),
        actions: renderActions(),
      ),
      body: SimplePullLoadWidget(
        pullLoadManger: manger,
      ),
    );
  }
}
